package batframework.mvc.render;

import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.ServletException;

import batframework.code.util.Assert;
import batframework.mvc.exception.RenderException;


/**
 * 
 * @author bmyues
 *
 */
public class JspRender extends AbstractRender
{
	private final static String contentType = "text/html";
	
	private String view;
	
	public void render()
	{
		try{
			Map<String, Object> attrs = model.getAttrs();
			for (Entry<String, Object> en : attrs.entrySet())
				request.setAttribute(en.getKey(), en.getValue());
			response.setContentType(contentType);
			request.getRequestDispatcher(view).forward(request, response);
		} catch (ServletException e){
			throw new RenderException(e);
		} catch (IOException e){
			throw new RenderException(e);
		}
	}
	
	/**
	 * 
	 * @ author bmyues
	 * @param view
	 */
	public JspRender(String view)
	{
		Assert.notNull(view);
		this.view = view;
	}
	
	public JspRender setView(String view)
	{
		this.view = view;
		return this;
	}

	public JspRender()
	{
		super();
	}
	
	
	
}
